package com.ruoyi.project.business.order.controller;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.book.domain.Book2;
import com.ruoyi.project.business.order.domain.Order;
import com.ruoyi.project.business.order.service.OrderService;
import io.swagger.models.auth.In;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 分类Controller
 * 
 * @author ruoyi
 * @date 2022-04-09
 */
@Controller
@RequestMapping("/business/order")
public class OrderController extends BaseController
{
    private String prefix = "business/order";

    @Autowired
    private OrderService orderService;

    // @RequiresPermissions("business:book:view")
    @GetMapping()
    public String book()
    {
        return prefix + "/order";
    }

    /**
     * 查询分类列表
     */
    // @RequiresPermissions("business:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    // @RequiresPermissions("business:book:edit")
    @GetMapping("/query/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        Order order2 = new Order();
        order2.setId(id);
        List<Order> orders = orderService.selectOrderList(order2);
        Order order =orders.get(0);
        mmap.put("order", order);
        return prefix + "/edit";
    }

    /**
     * 订单发货
     * @param id
     * @return
     */
    @GetMapping("/submit")
    @ResponseBody
    public Map<String,Object> submit(@RequestParam("id") Integer id){
        orderService.updateOrderStatus(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg","ok");
        return map;
    }

    // @GetMapping("/list")
    // @ResponseBody
    // public String list()
    // {
    //     // startPage();
    //     List<Order> list = orderService.selectOrderList(null);
    //     return JSON.toJSONString(list);
    //
    // }



    // /**
    //  * 导出分类列表
    //  */
    // @RequiresPermissions("business:fenlei:export")
    // @Log(title = "分类", businessType = BusinessType.EXPORT)
    // @PostMapping("/export")
    // @ResponseBody
    // public AjaxResult export(Fenlei fenlei)
    // {
    //     List<Fenlei> list = fenleiService.selectFenleiList(fenlei);
    //     ExcelUtil<Fenlei> util = new ExcelUtil<Fenlei>(Fenlei.class);
    //     return util.exportExcel(list, "分类数据");
    // }


}
